package com.cema.manage.project.android.utils;

import com.cema.manage.common.exception.DemoModeException;
import com.cema.manage.common.utils.StringUtils;

public class AssertUtils {

    //  空则报错
    public static void isNull(Object object, String message) {
        if (object == null) {
            throw new DemoModeException(message);
        }
        if (object instanceof String) {
            if (StringUtils.isEmpty((String) object)) {
                throw new DemoModeException(message);
            }
        }
    }

    // 若不为信用码则报错
    public static void isNotLicense(String num, String message) {
        if (!ValidatorUtils.isLicense15(num) && !ValidatorUtils.isLicense18(num)) {
            throw new DemoModeException(message);
        }
    }

    // 若不为手机号则报错
    public static void isNotMobile(String mobile, String message) {
        if (!ValidatorUtils.isMobile(mobile)) {
            throw new DemoModeException(message);
        }
    }

    // 若不为邮箱格式则报错
    public static void isNotEmail(String email, String message) {
        if (!ValidatorUtils.isEmail(email)) {
            throw new DemoModeException(message);
        }
    }

    // 若不为邮箱格式则报错
    public static void checkPwd(String email, String message) {
        if (!ValidatorUtils.checkPwd(email)) {
            throw new DemoModeException(message);
        }
    }

    // 为true则报错
    public static void isTrue(boolean flag, String message) {
        if (flag) {
            throw new DemoModeException(message);
        }
    }

    // 为false则报错
    public static void isFalse(boolean flag, String message) {
        isTrue(!flag, message);
    }
}